<template>
  <div class="note-pad">
    <textarea
      class="content"
      placeholder=" 随便记点什么吧..."
      spellcheck="false"
      v-model="notePadContent"
    ></textarea>
    <!-- <i class="fa fa-close" title="清空所有内容" @click="clear"></i> -->
    <i class="fa fa-trash-o fa-lg" title="清空所有内容" @click="clear"></i>
  </div>
</template>

<script>
export default {
  name: "NotePad",
  data() {
    return {
      notePadContent: window.localStorage.getItem("notePadContent") || ""
    }
  },
  methods: {
    clear() {
      if (this.notePadContent && confirm("确定清空记事本吗？")) {
        window.localStorage.removeItem("notePadContent")
        // 系统自带的清空
        this.notePadContent = ""
      }
    }
  },
  watch: {
    notePadContent(newValue) {
      window.localStorage.setItem("notePadContent", newValue)
    }
  }
}
</script>

<style lang="less" scoped>
.note-pad {
  position: relative;
  width: 70%;
  height: 80%;
  margin: 0 auto;
  background: #fef9e7;
  padding: 16px 24px;
  margin-top: 20px;
  border-radius: 4px;
  box-shadow: 0 0 4px #b2babb;
}
.content {
  width: 100%;
  max-width: 100%;
  min-width: 100%;
  height: 100%;
  background: linear-gradient(transparent 95%, rgba(52, 73, 94, 0.5) 0);
  line-height: 2em;
  background-size: 100% 2em;
  background-attachment: local;
  border: none;
  resize: none;
}
/*滚动条整体样式*/
.content::-webkit-scrollbar {
  width: 5px; /*高宽分别对应横竖滚动条的尺寸*/
}
.content::-webkit-scrollbar-thumb {
  /*滚动条里面小方块*/
  border-radius: 10px;
  box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.1);
  background: #535353;
}
.test-1::-webkit-scrollbar-track {
  /*滚动条里面轨道*/
  box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
  border-radius: 10px;
  background: transparent;
}
.content:focus {
  outline: none;
}
.fa-trash-o {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 30px;
  height: 30px;
  line-height: 30px;
  border-radius: 15px;
  text-align: center;
  color: gray;
  transition: 0.3s;
}
.fa-trash-o:hover {
  color: #fff;
  background-color: gray;
}
</style>
